package com.itheima.controller.ums;

import com.itheima.core.R;
import com.itheima.pojo.ums.UmsResourceCategory;
import com.itheima.service.ums.UmsResourceCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/resourceCategory")
public class UmsResourceCategoryController {
    @DubboReference
    private UmsResourceCategoryService umsResourceCategoryService;

    /**
     * 添加后台资源分类
     *
     * @param umsResourceCategory
     * @return
     */
    @PostMapping("/create")
    public R create(@RequestBody UmsResourceCategory umsResourceCategory) {
        umsResourceCategoryService.create(umsResourceCategory);
        return R.success("success");
    }

    /**
     * 根据ID删除后台资源
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Integer id) {
        umsResourceCategoryService.delete(id);
        return R.success("success");
    }

    /**
     * 查询所有后台资源分类
     *
     * @return
     */
    @GetMapping("/listAll")
    public R listAll() {
        List<UmsResourceCategory> listAll = umsResourceCategoryService.listAll();
        return R.success(listAll);
    }

    /**
     * 修改后台资源分类
     *
     * @param umsResourceCategory
     * @return
     */
    @PostMapping("/update/{id}")
    public R update(@RequestBody UmsResourceCategory umsResourceCategory) {
        boolean res = umsResourceCategoryService.updateResource(umsResourceCategory);
        return res == true ? R.success() : R.error("此id不存在！");
    }
}
